<%@page import="com.sun.java.swing.plaf.windows.resources.windows"%>
<%@page import="javax.servlet.*"%>
<%@ page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Reindirizzamento</title>
</head>
<body>
<%
	String username = request.getParameter("username");
	String password = request.getParameter("password");
	String tipologia ;//= request.getParameter("tipologiaprofilo");
	
	session.setAttribute("id",username);
	session.setAttribute("ps",password);

	Class.forName("oracle.jdbc.driver.OracleDriver");
	Connection con = DriverManager.getConnection(
			"jdbc:oracle:thin:@localhost:1521:xe", "aziendavinicola",
			"filippo");

	session.setAttribute("connection", con);
	
	Statement st = con.createStatement();

	ResultSet rs = st.executeQuery("Select * from accountutente");

	boolean redirected = false;

	while (rs.next()) {

		if (rs.getString("USERNAME").equals(username) && rs.getString("PASSWORD").equals(password))
			if (rs.getString("TIPOLOGIAPROFILO").equals("Manager")) {
				response.sendRedirect("../UtenteManager/menuManager.jsp");
			if (rs.getString("TIPOLOGIAPROFILO").equals("Manager")) {
				response.sendRedirect("./UtenteManager/menuManager.jsp");
				redirected = true;
			} 
		else if (rs.getString("USERNAME").equals(username)&& rs.getString("PASSWORD").equals(password))
			if (rs.getString("TIPOLOGIAPROFILO").equals("Amministratore")) {
				response.sendRedirect("./UtenteAmministratore/MenuAmministratore.jsp");
				redirected = true;
				}
		else if (rs.getString("USERNAME").equals(username)&& rs.getString("PASSWORD").equals(password))
			if (rs.getString("TIPOLOGIAPROFILO").equals("Cliente")) {
	
				response.sendRedirect("./UtenteCliente/Cliente.jsp");
				redirected = true;
				}
	}
	if (redirected == false)
		response.sendRedirect("login2.html");
%>

</body>
</html>